package com.tenbent.product.center.example.stu.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tenbent.product.base.dto.BaseDto;
import com.tenbent.product.center.example.stu.bo.Student;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * DTO
 * <p>
 * Created by ThinkPad on 2017/8/4.
 */
@ApiModel(value = "学生信息")
public class StudentDto extends BaseDto {

	@ApiModelProperty(name = "学生名称", value = "name", required = true)
	@NotNull(message = "{name.not.empty}")
	@Size(min = 8, max = 16, message = "{name.between.size}")
	private String name;

	@ApiModelProperty(name = "学生年龄", value = "age")
	private Integer age;

	@ApiModelProperty(name = "学生所属部门", value = "deptId")
	private Integer deptId;

	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date date;

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date dateTime;

	public StudentDto() {

	}

	public StudentDto(Student student) {
		super(student);
		setName(student.getName());
		setAge(student.getAge());
		setDeptId(student.getDeptId());
		setDate(student.getCreateDate());
		setDateTime(student.getModifyDate());
	}

	public Student transToBo() {
		Student stu = new Student();
		super.transToBo(stu);
		stu.setName(this.getName());
		stu.setAge(this.getAge());
		stu.setDeptId(this.getDeptId());
		return stu;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public Integer getDeptId() {
		return deptId;
	}

	public void setDeptId(Integer deptId) {
		this.deptId = deptId;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getDateTime() {
		return dateTime;
	}

	public void setDateTime(Date dateTime) {
		this.dateTime = dateTime;
	}

}
